<?php

namespace Home\Controller;

use Home\Service\RSOBillService;
use Home\Service\UserService;
use Home\Common\FIdConst;
use Home\Service\RPOBillService;

/**
 * 订单关联Controller
 *
 * @author linbo
 *        
 */
class BillRelationController extends PSIBaseController {

    /**
     * 采购订单关联 - 主页面
     */
    public function poRelationIndex() {
        $us = new UserService();

        if ($us->hasPermission(FIdConst::PURCHASE_ORDER_RELATION)) {
            $this->initVar();

            $this->assign("title", "采购关联订单");

            $this->assign("pConfirm",
                $us->hasPermission(FIdConst::PURCHASE_ORDER_CONFIRM) ? "1" : "0");
            $this->assign("pGenPWBill",
                $us->hasPermission(FIdConst::PURCHASE_ORDER_GEN_PWBILL) ? "1" : "0");

            $this->display();
        } else {
            $this->gotoLoginPage("/Home/Purchase/pobillIndex");
        }
    }

    /**
     * 获得采购关联订单主表信息列表
     */
    public function rpobillList() {
        if (IS_POST) {
            $ps = new RPOBillService();
            $params = array(
                "billStatus" => I("post.billStatus"),
                "ref" => I("post.ref"),
                "start" => I("post.start"),
                "limit" => I("post.limit")
            );
            $this->ajaxReturn($ps->pobillList($params));
        }
    }

    /**
     * 删除采购关联订单
     */
    public function deleteRPOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RPOBillService();
            $this->ajaxReturn($ps->deletePOBill($params));
        }
    }

    /**
     * 新增或编辑采购关联订单
     */
    public function editRPOBill() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->editPOBill($json));
        }
    }

    /**
     * 获得采购关联订单的信息
     */
    public function rpoBillInfo() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RPOBillService();
            $this->ajaxReturn($ps->poBillInfo($params));
        }
    }

    /**
     * 获得采购关联订单的明细信息
     */
    public function rpoBillDetail2List() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id"),
                "selectIds" => I("post.selectIds")
            );
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->poBillDetail2List($params));
        }
    }

    /**
     * 获得采购关联销售订单的明细信息
     */
    public function rpoBillDetail3List() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->poBillDetail3List($params));
        }
    }

    /**
     * 审核采购关联订单
     */
    public function commitRPOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RPOBillService();
            $this->ajaxReturn($ps->commitPOBill($params));
        }
    }

    /**
     * 取消审核采购关联订单
     */
    public function cancelConfirmRPOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RPOBillService();
            $this->ajaxReturn($ps->cancelConfirmPOBill($params));
        }
    }

    /**
     * 获得采购订单未添加信息列表
     */
    public function rpoEditBillList() {
        if (IS_POST) {
            $ps = new RPOBillService();
            $params = array(
                "billStatus" => I("post.billStatus"),
                "ref" => I("post.ref"),
                "fromDT" => I("post.fromDT"),
                "toDT" => I("post.toDT"),
                "supplierId" => I("post.supplierId"),
                "paymentType" => I("post.paymentType"),
                "start" => I("post.start"),
                "limit" => I("post.limit"),
                "selectIds" => I("post.selectIds")
            );
            $this->ajaxReturn($ps->rpoEditBillList($params));
        }
    }

    /**
     * 新增关联关系
     */
    public function addRPORelation() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->addRPORelation($json));
        }
    }

    /**
     * 移除关联关系
     */
    public function removeRPORelation() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->removeRPORelation($json));
        }
    }

    /**
     * 获得采购订单的明细信息
     */
    public function poBillDetailList() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RPOBillService();
            $this->ajaxReturn($ps->poBillDetailList($params));
        }
    }

    /**
     * 新增采购关联订单
     */
    public function addRPOBillSale() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->addRPOBillSale($json));
        }
    }

    /**
     * 移除采购关联销售订单
     */
    public function removeRPOBillSale() {

        if (IS_POST) {

            $id = I("post.id");
            $ps = new RPOBillService();
            $this->ajaxReturn($ps->removeRPOBillSale($id));
        }
    }


    //========================================

    /**
     * 销售关联订单 - 主页面
     */
    public function soRelationIndex() {
        $us = new UserService();

        if ($us->hasPermission(FIdConst::SALE_ORDER)) {
            $this->initVar();

            $this->assign("title", "销售关联订单");

            $this->assign("pConfirm", $us->hasPermission(FIdConst::SALE_ORDER_CONFIRM) ? "1" : "0");
            $this->assign("pGenWSBill",
                $us->hasPermission(FIdConst::SALE_ORDER_GEN_WSBILL) ? "1" : "0");

            $this->display();
        } else {
            $this->gotoLoginPage("/Home/Sale/soIndex");
        }
    }

    /**
     * 获得采购关联订单主表信息列表
     */
    public function rsobillList() {
        if (IS_POST) {
            $ps = new RSOBillService();
            $params = array(
                "billStatus" => I("post.billStatus"),
                "ref" => I("post.ref"),
                "start" => I("post.start"),
                "limit" => I("post.limit")
            );
            $this->ajaxReturn($ps->sobillList($params));
        }
    }

    /**
     * 删除采购关联订单
     */
    public function deleteRSOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RSOBillService();
            $this->ajaxReturn($ps->deleteSOBill($params));
        }
    }

    /**
     * 新增或编辑采购关联订单
     */
    public function editRSOBill() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->editSOBill($json));
        }
    }

    /**
     * 获得采购关联订单的信息
     */
    public function rsoBillInfo() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RSOBillService();
            $this->ajaxReturn($ps->soBillInfo($params));
        }
    }

    /**
     * 获得采购关联订单的明细信息
     */
    public function rsoBillDetailList() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RSOBillService();
            $this->ajaxReturn($ps->soBillDetailList($params));
        }
    }

    /**
     * 审核采购关联订单
     */
    public function commitRSOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RSOBillService();
            $this->ajaxReturn($ps->commitSOBill($params));
        }
    }

    /**
     * 取消审核采购关联订单
     */
    public function cancelConfirmRSOBill() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );

            $ps = new RSOBillService();
            $this->ajaxReturn($ps->cancelConfirmSOBill($params));
        }
    }

    /**
     * 获得销售订单未添加信息列表
     */
    public function rsoEditBillList() {
        if (IS_POST) {
            $ps = new RSOBillService();
            $params = array(
                "billStatus" => I("post.billStatus"),
                "ref" => I("post.ref"),
                "fromDT" => I("post.fromDT"),
                "toDT" => I("post.toDT"),
                "customerId" => I("post.customerId"),
                "receivingType" => I("post.receivingType"),
                "start" => I("post.start"),
                "limit" => I("post.limit"),
                "selectIds" => I("post.selectIds")
            );
            $this->ajaxReturn($ps->rsoEditBillList($params));
        }
    }

    /**
     * 新增关联关系
     */
    public function addRSORelation() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->addRSORelation($json));
        }
    }

    /**
     * 移除关联关系
     */
    public function removeRSORelation() {

        if (IS_POST) {

            $json = I("post.jsonStr");
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->removeRSORelation($json));
        }
    }

    /**
     * 获得采购关联订单的明细信息
     */
    public function rsoBillDetail2List() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id"),
                "selectIds" => I("post.selectIds")
            );
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->soBillDetail2List($params));
        }
    }

    /**
     * 获得采购关联销售订单的明细信息
     */
    public function rsoBillDetail3List() {
        if (IS_POST) {
            $params = array(
                "id" => I("post.id")
            );
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->soBillDetail3List($params));
        }
    }

    /**
     * 新增销售关联订单
     */
    public function addRSOBillPurchase() {

        if (IS_POST) {
            $json = I("post.jsonStr");
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->addRSOBillPurchase($json));
        }
    }

    /**
     * 移除采购关联销售订单
     */
    public function removeRSOBillPurchase() {

        if (IS_POST) {

            $id = I("post.id");
            $ps = new RSOBillService();
            $this->ajaxReturn($ps->removeRSOBillPurchase($id));
        }
    }
}